package com.starview.star.operators.misc.runtime;

import com.starview.platform.data.EvaluationException;
import com.starview.platform.data.IFunction;
import com.starview.platform.data.IValue;
import com.starview.platform.data.type.IType;
import com.starview.platform.data.type.Refresher;
import com.starview.platform.data.type.StandardTypes;
import com.starview.platform.data.type.TypeUtils;
import com.starview.platform.data.type.TypeVar;
import com.starview.platform.data.value.Factory;
import com.starview.star.operators.CafeEnter;

public class HashCode implements IFunction
{
  public static final String name = "__hashCode";

  @CafeEnter
  public static int enter(IValue obj)
  {
    return obj.hashCode();
  }

  @Override
  public IValue enter(IValue... args) throws EvaluationException
  {
    return Factory.newInt(enter(args[0]));
  }

  @Override
  public IType getType()
  {
    return type();
  }

  public static IType type()
  {
    return Refresher.generalize(TypeUtils.functionType(new TypeVar(), StandardTypes.rawIntegerType));
  }
}